﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Code4Public.Parsing
{
    public class DelimiterInfo
    {
        public string DelimStartsWith = "";
        public string DelimEndsWith = "";
        public string[] DelimEscapes = new string[0];

        public ExpressionType DelimType = ExpressionType.Newline;
        public string DelimGroup = "";

        public bool IsInsideDelim = false;
        public string DelimitedContentSoFar = "";

        public DelimiterInfo(string delimStartWith, string delimEndsWith, string[] delimEscapes,
            ExpressionType delimType, string delimGroup, bool isInsideDelim, string delimitedContent)
        {
            this.DelimStartsWith = delimStartWith;
            this.DelimEndsWith = delimEndsWith;
            this.DelimEscapes = delimEscapes;
            this.DelimType = delimType;
            this.DelimGroup = delimGroup;
            this.IsInsideDelim = isInsideDelim;
            this.DelimitedContentSoFar = delimitedContent;
        }

        /// <summary>
        /// gets whether this object represents a delimiter which is bound to only one line
        /// such as comment-line in C++ starting with //
        /// as oppossed to comment-blocks delimited between /* and */
        /// </summary>
        public bool IsOneLineDelimiter
        {
            get
            {
                return DelimEndsWith.Length <= 0;
            }
        }

        /// <summary>
        /// Gets an empty DelimInfo
        /// </summary>
        public static DelimiterInfo EmptyDelimInfo
        {
            get
            {
                return new DelimiterInfo("", "", new string[0], ExpressionType.Newline, "", false, "");
            }
        }

        /// <summary>
        /// returns an instance containing exact copy of the values of DelimiterInfo
        /// </summary>
        public static DelimiterInfo Copy(DelimiterInfo other)
        {
            return new DelimiterInfo(other.DelimStartsWith, other.DelimEndsWith, other.DelimEscapes, 
                other.DelimType, other.DelimGroup, other.IsInsideDelim, other.DelimitedContentSoFar);
        }
    }
}
